//
//  FreshFoodTableViewCell.m
//  Youhuiju
//
//  Created by yutenys on 16/7/22.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "FreshFoodTableViewCell.h"
#import "FreshFoodCollectionViewCell.h"
@interface FreshFoodTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (weak, nonatomic) IBOutlet UIButton *moreBtn;//查看更多

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIImageView *sectionImg;

//适配
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleImgHig;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnTrailing;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnHig;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnWid;


@end

@implementation FreshFoodTableViewCell

static NSString *FreshFoodCollectionViewCellIden = @"FreshFoodCollectionViewCellIden";
- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.titleImgHig.constant = 50 * FitH;
    self.moreBtnTrailing.constant = 20 * FitW;
    self.moreBtnHig.constant = 30 * FitH;
    self.moreBtnWid.constant = 50 * FitW;
    self.moreBtn.titleLabel.font = [UIFont systemFontOfSize:11 * FitH];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"FreshFoodCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:FreshFoodCollectionViewCellIden];
    
    // Initialization code
    
    
    
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FreshFoodCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:FreshFoodCollectionViewCellIden forIndexPath:indexPath];
    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(187 * FitW, 92 * FitH);
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 1 * FitH;
}
//
//-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
//{
//    return  UIEdgeInsetsMake(0, 0, 0, 0);
//}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    DLog(@"这是第%ld个item",indexPath.row);
    [self.clickedCellJumpDelegate freshClickedCellJump];
}

- (IBAction)moreBtnAction:(UIButton *)sender {
    if (self.moreBtnClickHandler)
    {
        self.moreBtnClickHandler();
    }
}

#pragma amrk --- setter
-(void)setImgUrl:(NSString *)imgUrl
{
    if (_imgUrl != imgUrl)
    {
        _imgUrl = imgUrl;
        
        self.sectionImg.image = LoadImage(imgUrl);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
